package com.example.controller;

import com.example.pojo.Musiclist;
import com.example.service.musicListImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Controller
@ResponseBody
@CrossOrigin(origins = "*", maxAge = 3600)
public class addmusic {
    @Autowired
    private musicListImp list1;
    @PostMapping(value = "/addMusic")//, headers = " 'content-type': 'application/json'"
    @CrossOrigin(origins = "*", maxAge = 3600)
    public String addMusic(@RequestBody Map<String, String> params) {
        String musicer = params.get("Musicer");
        String musicName = params.get("MusicName");
        String musicUrl = params.get("MusicUrl");
        List<Musiclist> existMusic = list1.selectByName(musicName);
        String res ="";
        if(existMusic.size()==0){
         res=list1.addMusic(musicer, musicName, musicUrl);
        }else {
            res="歌曲已存在";
        }
        return res;
    }
}
